package cn.web.provider.dubboConfig.configuration;


import cn.web.provider.dubboConfig.runner.DubboServiceLatchCommandLineRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(
        ignoreResourceNotFound = true,
        encoding = "utf-8",
        value = {"classpath:dubbo.properties"}
)
@ImportResource(locations = {"classpath:dubboService.xml"})
public class DubboAutoConfiguration {

    //先去application.properties里边去查找shutdown.latch.domain.name,如果没有则使用com.test
    @Value("${shutdown.latch.domain.name:com.test}")
    private String shutdownLatchDomainName;

    public DubboAutoConfiguration() {
    }

    @Bean
    @ConditionalOnNotWebApplication
    public DubboServiceLatchCommandLineRunner configureDubboServiceLatchCommandLineRunner() {
        System.out.println(shutdownLatchDomainName);
        System.out.println("DubboAutoConfiguration enabled by adding DubboServiceLatchCommandLineRunner");
        DubboServiceLatchCommandLineRunner runner = new DubboServiceLatchCommandLineRunner();
        runner.setDomain(this.shutdownLatchDomainName);
        return runner;
    }

}
